package com.sugar.psych.assessment.module.business.controller.admin.userpointsrecord;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.success;

import com.sugar.psych.assessment.framework.excel.core.util.ExcelUtils;

import com.sugar.psych.assessment.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.psych.assessment.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.psych.assessment.module.business.controller.admin.userpointsrecord.vo.*;
import com.sugar.psych.assessment.module.business.dal.dataobject.userpointsrecord.UserPointsRecordDO;
import com.sugar.psych.assessment.module.business.service.userpointsrecord.UserPointsRecordService;

@Tag(name = "管理后台 - 用户积分记录")
@RestController
@RequestMapping("/business/user-points-record")
@Validated
public class UserPointsRecordController {

    @Resource
    private UserPointsRecordService userPointsRecordService;

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户积分记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:user-points-record:delete')")
    public CommonResult<Boolean> deleteUserPointsRecord(@RequestParam("id") Long id) {
        userPointsRecordService.deleteUserPointsRecord(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除用户积分记录")
                @PreAuthorize("@ss.hasPermission('business:user-points-record:delete')")
    public CommonResult<Boolean> deleteUserPointsRecordList(@RequestParam("ids") List<Long> ids) {
        userPointsRecordService.deleteUserPointsRecordListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户积分记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:user-points-record:query')")
    public CommonResult<UserPointsRecordRespVO> getUserPointsRecord(@RequestParam("id") Long id) {
        UserPointsRecordDO userPointsRecord = userPointsRecordService.getUserPointsRecord(id);
        return success(BeanUtils.toBean(userPointsRecord, UserPointsRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户积分记录分页")
    @PreAuthorize("@ss.hasPermission('business:user-points-record:query')")
    public CommonResult<PageResult<UserPointsRecordRespVO>> getUserPointsRecordPage(@Valid UserPointsRecordPageReqVO pageReqVO) {
        return success(userPointsRecordService.getUserPointsRecordPage(pageReqVO));
    }
}